package main

import (
	"fmt"
	"os"
	"text/template"
)

// CrossSserver
const tplLogicServerLinuxTxt = `
-- LogicServerLinux.txt 模板:
LogicServer =
{
    ServerName = "版本验收-逻辑服(sid=1002)",
    ServerIndex = 2,
    ServerOpenTime  = "2024-01-11 6:00:00",  
    --ServerCombineTime = "2023-12-21 8:00:00",
    spguid=1,

    --sdk
    SdkServer =  
    {
        Address ="127.0.0.1",
        Port = 32000
    },

    --监听：网关服务器
    GateService = 
    { 
        Address = "0.0.0.0", 
        Port = 23103
    },

    --连接：数据服务器
    DbServer = 
    {
        Address = "127.0.0.1", 
        Port = 32103
    },

    --连接：LocalLog服务器
    LocalLogServer = 
    {
        Address = "127.0.0.1", 
        Port = 33112
    },

    --连接：会话服务器
    SessionServer = 
    {
        Address = "127.0.0.1",
        Port = 31000
    },

    --连接：Log服务器
    LogServer = 
    {
        Address = "127.0.0.1", 
        Port = 34000
    },

    --连接：AM服务器
    AMServer = 
    {
        Host = "{{.ip}}",
        Port = {{.port}}
    },

    --连接：后台服务器
    MgrServer = 
    {
        Host = "127.0.0.1", 
        Port = 8500,
    },
}`

const tplDBServerLinuxTxt = `
DBServer =
{
	--服务器名称
	ServerName = "版本验收-数据服(sid=10001)",
	ServerIndex = 10001,

	--随机生成名字的名字库文件的文件名,相对路径
	BoyNameFile = "BoyNameList.dat",
	GirlNameFile = "GirlNameList.dat",
	utf8=1,

	--监听：数据服务
	DBService = 
	{ 
		Address = "0.0.0.0", 
		Port = 42102
	},

	--连接：会话服务器
	--SessionServer = 
	--{ 
	--	Address = "127.0.0.1", 
	--	Port = 31000
	--},

	--连接：日志服务器
	LogServer = 
	{ 
		Address = "127.0.0.1", 
		Port = 34000
	},

	--连接：名称服务器
	NameServer = 
	{ 
		Address = "127.0.0.1", 
		--Address = "192.168.0.207", 
		Port = 35000
	},
    
	--连接：跨服的DB
	--DBCenter = 
	--{
	--	Address = "127.0.0.1", 
	--	Port = 36000
	--},

	--数据库连接配置
	SQL = 
	{ 
		Host = "47.107.60.178", 	
		Port = 3306, 
		DBName = "actor_cross1",
		DBUser = "cq3d",
		DBPass = "Sansemi2013",
	}
}
`

const tplLocalLogServerTxt = `
LocalLogServer = 
{
	spguid = 1,

	--监听：服务器参数配置
	Server = 
	{ 
		BindAddress = "0.0.0.0", 
		Port = 33103,
		ServiceName="LoggerServer",
	},
	
	--监听：发送聊天消息给工具
	ChatLog = 
	{ 
		ServiceName="LogServer",
		BindAddress = "0.0.0.0", 
		Port = 35011,
	},

	--数据库连接相关
	SQL = 
	{
		Host = "47.107.60.178", 	
		Port = 3306, 
		DBName = "log_local_s4", 
		DBUser = "cq3d", 
		DBPass = "Sansemi2013",
		utf8=1,
	},
}
`

const tplGateServerTxt = `
GateServer =
{
	--逻辑网关
	{
		--网关服务的绑定地址和端口
		LocalService =
		{
				ServerName = "跨服网关",
				Address =  "0.0.0.0",
				Port = 10001,
				MaxSession = 8192,--网关中客户端连接池的最大连接数
				SendThreadCount = 2,--数据发送线程池中工作线程数量
		},
		--后台服务器的地址和端口
		BackServer =
		{
				Host = "127.0.0.1",
				Port = 43101
		},
	},
}`

// Public
const tplBackStageServerLinuxTxt = `
BackServer = 
{
	spguid = 1,		--默认的spid

	--监听：服务器参数配置
	Server = 
	{ 
		ServiceName="BackStageServer",
		BindAddress = "0.0.0.0", 
		Port = 8500 ,
		HttpPort = 111,
	},

	--数据库连接相关
	SQL = 
	{ 
		Host = "47.107.60.178",
		Port = 3306, 
		DBName = "zgame_command", 
		DBUser = "cq3d", 
		DBPass = "Sansemi2013",
		utf8=1,
	},
}
`

const LoggerServerLinux = `
LoggerServer = 
{
	--监听：服务器参数配置
	Server = 
	{ 
		BindAddress = "0.0.0.0", 
		Port = 34000 ,
		ServiceName="LoggerServer",
	},
	
	--监听：发送聊天消息给工具
	ChatLog = 
	{ 
		ServiceName="LogServer",
		BindAddress = "0.0.0.0", 
		Port = 35010,
	},

	--数据库连接相关
	SQL = 
	{
		Host = "47.107.60.178", 	
		Port = 3306, 
		DBName = "log_s1", 
		DBUser = "cq3d", 
		DBPass = "Sansemi2013",
		utf8=1,
	},
}
`
const tplNameServerLinuxTxt = `
NameServer =
{
	--服务器名称
	ServerName = "zgame-nameserver",
    spguid=1,
        
	--监听：名称服务绑定地址和端口
	NameService = 
	{ 
		Address = "0.0.0.0", 
		Port = 35000 
	},

	--数据库连接配置
	SQL = 
	{ 
		--Host = "192.168.0.173", 	
		Host = "47.107.60.178", 
		Port = 3306, 
		DBName = "zgame_name", 
		DBUser = "cq3d", 
		DBPass = "Sansemi2013" 
	}
}
`
const tplServerSetting = `
{
	"account_db": {
		"addr": "47.107.60.178",
		"port": 3306,
		"user": "cq3d",
		"pwd": "Sansemi2013",
		"db": "mmo_account"
	},
	"tcp": {
		"ip": "0.0.0.0",
		"port": 32000
	},
	"http": {
		"ip": "0.0.0.0",
		"port": 33000
	},
	"channel": "XiaoMan"
}
`
const tplSessionServerLinuxTxt = `
{
	"account_db": {
		"addr": "47.107.60.178",
		"port": 3306,
		"user": "cq3d",
		"pwd": "Sansemi2013",
		"db": "mmo_account"
	},
	"tcp": {
		"ip": "0.0.0.0",
		"port": 32000
	},
	"http": {
		"ip": "0.0.0.0",
		"port": 33000
	},
	"channel": "XiaoMan"
}
`

func runBusiness(args []string) {
	//业务主程序代码
	fmt.Printf("start test Service: %s\n", os.Args[1])

	// 解析模板
	tmpl, _ := template.New("test").Parse(tplLogicServerLinuxTxt)

	// 数据驱动模板
	data := map[string]interface{}{
		"ip":   "127.0.0.1",
		"port": 5660,
	}
	_ = tmpl.Execute(os.Stdout, data)

	fmt.Println("Hello,World!")
}
